<template>
	<view class="page" style="height:100vh;background: #ededed;">
		<free-nav-bar showback :showright="false" title="添加好友">


		</free-nav-bar>
		<view class="flex flex-column">
			<text class="font-sm text-secondary px-3 py-2">备注名</text>
			<input type="text" style="height: 100rpx;" class="font-md px-3 border bg-white" v-model="form.nickname"
				placeholder="请输入备注名">
		</view>
		<free-list-item title="不让他看我" showright :isshowjt="false">
			<switch :checked="form.lookme" @change="brtkw" v-model="form.lookme" slot="right" />
		</free-list-item>
		<free-list-item title="不看他" showright :isshowjt="false">
			<switch :checked="form.lookhim" @change="bkt" v-model="form.lookhim" slot="right" />
		</free-list-item>
		<view class="py-3 flex align-center justify-center bg-white" hover-class="bg-light" @click="submit">
			<text class="font-md text-primary">确认添加</text>
		</view>
	</view>
</template>

<script>
	import freeNavBar from "@/components/free-ui/free-nav-bar.vue"
	import freeListItem from "@/components/free-ui/free-list-item.vue"
	import $H from '../../../utils/request.js';
	export default {
		components: {
			freeNavBar,
			freeListItem
		},
		data() {
			return {
				form: {
					friend_id: 0,
					nickname: "",
					lookme: false,
					lookhim: false,

				},
				text:""
			}
		},
		onLoad(e) {
			this.text=e.text
			console.log(e, "e")
			this.form.friend_id = e.id
		},
		methods: {
			brtkw(e) {
				console.log(e, "e");
				this.form.lookme = e.detail.value
			},
			bkt(e) {
				console.log(e, "e");
				this.form.lookhim = e.detail.value
			},
			submit() {
				console.log(this.text,"text")
				if(this.text == "'添加好友'"){
					
					console.log(this.form.lookhim, this.form.lookme)
					
					let data = {
						friend_id: this.form.friend_id,
						nickname: this.form.nickname,
						lookme: this.form.lookme == true ? 1 : 0,
						lookhim: this.form.lookhim == true ? 1 : 0,
					
					}
					$H.post(`user/addFriend`, data, {
						token: true
					}).then(res => {
						console.log(res, "res")
						if(res){
							uni.showToast({
								title:"申请成功",
								icon:"success"
							})
							uni.navigateBack({
								delta:1
							})
						}
					})
				}else if(this.text == "'同意好友'"){
					console.log(1233,"1233");
					let data = {
						friend_id: this.form.friend_id,
						nickname: this.form.nickname,
						status:"agree",
						lookme: this.form.lookme == true ? 1 : 0,
						lookhim: this.form.lookhim == true ? 1 : 0,
					
					}
					$H.post(`apply/1/handle`, data, {
						token: true
					}).then(res => {
						console.log(res, "res")
						if(res){
							this.$store.dispatch("getApply")
							
							uni.showToast({
								title:"申请成功",
								icon:"success"
							})
							uni.navigateBack({
								delta:1
							})
					
						}
					})
				}
				
			}
		}
	}
</script>

<style>

</style>
